package ${entity.controllerPackage};

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import ${entity.entityPackage}.${entity.className?cap_first};
import ${entity.servicePackage}.${entity.className?cap_first}Service;
import per.ethan.cloud.common.domain.Page;
import per.ethan.cloud.common.domain.ResultBean;
import lombok.RequiredArgsConstructor;

import java.util.List;
import java.util.Map;

/**
* @author ${entity.authorName!}
* @date 2020/03/11 16:15
*/
@RestController
@RequestMapping("/${entity.className}")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class ${entity.className?cap_first}Controller{

    @Qualifier("${entity.className}Service")
    private final ${entity.className?cap_first}Service ${entity.className}Service;

    @PostMapping
    @ApiOperation(value = "保存实体信息")
    public ResultBean<Long> save${entity.className?cap_first}(@RequestBody ${entity.className?cap_first} ${entity.className}){
        return ResultBean.success(${entity.className}Service.save(${entity.className}));
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "通过id查询信息")
    public ResultBean<${entity.className?cap_first}> findById(@PathVariable Long id){
        return ResultBean.success(${entity.className}Service.findById(id));
    }

    @PostMapping("/page")
    @ApiOperation(value = "分页查询")
    public ResultBean<Page<${entity.className?cap_first}>> findByPage(@RequestBody Page<${entity.className?cap_first}> page) {
        return ResultBean.success(${entity.className}Service.findByPage(page));
    }

    @GetMapping("/getByWhere")
    @ApiOperation(value = "按条件查询信息")
    public ResultBean<List<${entity.className?cap_first}>> findByWhere(@RequestParam Map<String, Object> paramMap) {
        return ResultBean.success(${entity.className}Service.findByMap(paramMap));
    }

    @PutMapping
    @ApiOperation(value = "修改实体信息")
    public ResultBean<Boolean> modify(@RequestBody ${entity.className?cap_first} ${entity.className}) {
        return ResultBean.success(${entity.className}Service.update(${entity.className}));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除实体信息")
    public ResultBean<Boolean> removeById(@PathVariable Long id){
        return ResultBean.success(${entity.className}Service.logicDeleteById(id));
    }

    @DeleteMapping("/batchRemove")
    @ApiOperation(value = "批量删除实体信息")
    public ResultBean<Boolean> batchRemove(@RequestBody List<Long> idList){
        return ResultBean.success(${entity.className}Service.logicBatchDelete(idList));
    }

}
